package com.xiejr.pss.jvm.memory;

import org.openjdk.jol.info.ClassLayout;

/**
 * 对象内存结构分配
 *
 * @author mobai
 * @since 2021/6/11 19:52
 */
public class InstanceMemoryLayoutTest {

    public static void main(String[] args) {
        ClassLayout layout1 = ClassLayout.parseInstance(new Object());
        System.out.println(layout1.toPrintable());

//        ClassLayout layout = ClassLayout.parseInstance(new SingleTon());
//
//        System.out.println(layout.toPrintable());
    }

    static class SingleTon {
        //markword=8  kclass=4

        String name; //4

        int a = 1;//4

        long b = 1;//8

        byte[] arr = new byte[3];//3+1=4

        boolean flag;//1 +3

        //以上总和为36， jvm默认会对齐为8的平方,故最终应该是40

        //40

    }
}
